/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.insta.browser.view.webview;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Maarek
 */
class WebViewListenerCollection implements WebViewListener {

    final private List<WebViewListener> listeners = new ArrayList<>();

    /**
     * <p>addListener.</p>
     *
     * @param listener a {@link fr.insta.browser.view.webview.WebViewListener} object.
     */
    public void addListener(WebViewListener listener) {
        listeners.add(listener);
    }

    /**
     * <p>removeListener.</p>
     *
     * @param listener a {@link fr.insta.browser.view.webview.WebViewListener} object.
     */
    public void removeListener(WebViewListener listener) {
        listeners.remove(listener);
    }

    /** {@inheritDoc} */
    @Override
    public void onTitleChange(SwingWebView webView, String oldTitle, String newTitle) {
        for (WebViewListener webViewListener : listeners) {
            webViewListener.onTitleChange(webView, oldTitle, newTitle);
        }
    }

    /** {@inheritDoc} */
    @Override
    public void onLocationChange(SwingWebView webView, String oldLocation, String newLocation) {
        for (WebViewListener webViewListener : listeners) {
            webViewListener.onLocationChange(webView, oldLocation, newLocation);
        }
    }
}
